﻿using Nemerle.Collections;
using Nemerle.Text;
using Nemerle.Utility;
using Nemerle.Compiler;

using System;
using System.Collections.Generic;
using System.Linq;

using N2 = Nemerle2.Compiler;
using PT = Nemerle.Compiler.Parsetree;
using PEG = Nemerle.Peg;

namespace Nemerle2.Parser
{
  public partial class AstConverter
  {
    ConvertTypeDeclaration(env : GlobalEnv, decl : N2.PTypeDeclaration) : void
    {
      match(decl)
      {
        | MacroClass(members) =>
          def (grammar, handlers) = ConvertGrammar(env, members);
          def key = PegParserProxyMarshaller.Pass(manager, grammar);
          def decl = PT.TopDeclaration.Class(
            NLocation(decl),
            ConvertSplicable(env, decl.Name),
            Modifiers(NemerleAttributes.Public, [<[ Nemerle2.Parser.PegParserProxy($(key : string)) ]>]),
            PT.Typarms.Empty,
            [],
            handlers);
          typeDecls.Add(decl);

        | Alias
        | Enum
        | Struct
        | Interface
        | Variant
        | VariantOption
        | Delegate
        | Expr
        | Class => assert(false, "not implemented")

        | Error(msg) as loc => Echo(loc, msg);
      }
    }

    ConvertGrammar(env : GlobalEnv, members : N2.LocatedList[N2.PMember]) : PEG.Grammar * list[PT.ClassMember]
    {
      (PEG.Grammar(PEG.NameRef("start")), [])
    }
  }
}
